package com.rr.graphql.resolver;

import com.netflix.graphql.dgs.*;
import com.rr.constant.SexEnum;
import com.rr.dto.*;
import lombok.extern.slf4j.Slf4j;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;

/**
 * @author RR
 * @date 2023/6/24 11:59
 */
@DgsComponent
@Slf4j
public class ObjectGraphQLResolver {
    @DgsQuery(field = "listDepartmentAndEmployeeResponse")
    public List<Response> listDepartmentAndEmployeeResponse(){
        Department department = new Department();
        department.setId(UUID.randomUUID().toString());
        department.setName("软件工程");
        department.setEmployees(new ArrayList<>());
        Response departmentOf = new DepartmentResponse(department);

        Employee employee = new Employee();
        employee.setId(UUID.randomUUID().toString());
        employee.setName("zcr");
        employee.setSex(SexEnum.MALE);
        employee.setBirthday(LocalDateTime.now());
        Response employeeOf = new EmployeeResponse(employee);

        return Arrays.asList(departmentOf, employeeOf);
    }

    @DgsQuery(field = "listDepartmentAndEmployee")
    public List listDepartmentAndEmployee(){
        Department department = new Department();
        department.setId(UUID.randomUUID().toString());
        department.setName("软件工程");
        department.setEmployees(new ArrayList<>());

        Employee employee = new Employee();
        employee.setId(UUID.randomUUID().toString());
        employee.setName("zcr");
        employee.setSex(SexEnum.MALE);
        employee.setBirthday(LocalDateTime.now());

        return Arrays.asList(department, employee);
    }
}
